using System.Collections.Generic;
using Castle.ActiveRecord;

namespace KenEgozi.Com.Domain.Aggregates.Tag
{
	[ActiveRecord]
	public class Tag
	{
		private readonly int _id = default(int);
		private readonly Lifecycle _lifecycle = new Lifecycle(); 
		private string _name;
		private string _urlFriendlyName;
		private IList<Post.Post> _posts;

		[Property(Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public string Name
		{
			get { return _name; }
			internal set { _name = value; }
		}

		[Property(Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public string UrlFriendlyName
		{
			get { return _urlFriendlyName; }
			internal set { _urlFriendlyName = value; }
		}

		[HasAndBelongsToMany(
			Lazy = true,
			Table = "PostTagging",
			ColumnKey = "TagId",
			ColumnRef = "PostId",
			Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public virtual IList<Post.Post> Posts
		{
			get
			{
				if (_posts == null)
					_posts = new List<Post.Post>();
				return _posts;
			}
		}
		[PrimaryKey(Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public virtual int Id
		{
			get { return _id; }
		}

		[Nested(Access = PropertyAccess.NosetterCamelcaseUnderscore)]
		public virtual Lifecycle Lifecycle
		{
			get { return _lifecycle; }
		}
	}
}
